package com.dormitory.management.system.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dormitory.management.system.req.*;
import com.dormitory.management.system.resp.RepairResp;
import com.dormitory.management.system.service.RepairService;
import com.dormitory.managemnet.util.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 报修表 前端控制器
 * </p>
 *
 * @author
 * @since 2021-12-17
 */
@Api(tags = "维修管理")
@RestController
@RequestMapping("/repair")
public class RepairController {

    @Autowired
    private RepairService repairService;

    @ApiOperation("维修上报")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public Result<String> save(@RequestBody RepairSaveReq req){
        if(!repairService.save(req)) {
            return Result.error("该学生还未入住！");
        }
        return Result.success("上报成功！");
    }

    @ApiOperation("删除报单")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    public Result<String> delete(
            @ApiParam(value = "报单id",required = true)
            @PathVariable Long id){
        if(!repairService.delete(id)) {
            return Result.error("删除失败！");
        }
        return Result.success("删除成功！");
    }

    @ApiOperation("修改报单内容")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<String> update(@RequestBody RepairUpdateReq req){
        if(!repairService.update(req)) {
            return Result.error("更新失败！");
        }
        return Result.success("更新成功！");
    }

    @ApiOperation("维修报单申报")
    @RequestMapping(value = "/updateAppeal",method = RequestMethod.POST)
    public Result<String> updateAppeal(@RequestBody RepairAppealReq req){
        if(!repairService.updateAppeal(req)) {
            return Result.error("申报失败！");
        }
        return Result.success("申报成功！");
    }

    @ApiOperation("维修报单状态更新")
    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    public Result<String> updateStatus(@RequestBody RepairStatusReq req){
        if(!repairService.updateStatus(req)) {
            return Result.error("报单已完成，不可更新！");
        }
        return Result.success("状态更新成功！");
    }

    @ApiOperation("维修报单分页列表")
    @RequestMapping(value = "/getPage",method = RequestMethod.POST)
    public Result<IPage<RepairResp>> getPage(@RequestBody RepairPageReq req){
        return Result.ok(repairService.getPage(req));
    }











}
